/********************************************************************************
 * Copyright (c)2016-2020, ShenZhen WanJiaAn Technology CO.,LTD.
 * All Rights Reserved.
 *
 * File Name     : Audio.h
 * Author        : joki.zhu
 * Date          : 2019-10-19
 *
 * Record        :
 * 1.Date        : 2019-10-19
 *   Author      : joki.zhu
 *   Modification: Created file
 ********************************************************************************/

#ifndef __AUDIO_H__
#define __AUDIO_H__

#include "MediaPack.h"
#include "DevConfig.h"

#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */

/****************************************************************************************/
#define AUDIO_LINK_SUCCESS      "/res/audio/linksuccess.mp3"
#define AUDIO_LINK_FAIL         "/res/audio/linkfail.mp3"
#define AUDIO_START_CON         "/res/audio/startconfig.mp3"
#define AUDIO_QUIT_CON          "/res/audio/quitconfig.mp3"
#define AUDIO_RCVWAVE_SUCCESS   "/res/audio/rcvsuccess.mp3"
#define AUDIO_RESET_SUCCESS     "/res/audio/resetsuccess.mp3"
#define AUDIO_ALARM             "/res/audio/alarm.mp3"
#define AUDIO_CONFIG_SUCCESS    "/res/audio/configsuccess.mp3"
#define AUDIO_CONFIG_FAIL       "/res/audio/configfail.mp3"
#define AUDIO_POWER_OFF         "/res/audio/poweroff.mp3"

#define AUDIO_PLAY_VOL_DEFAULT      (100)
#define AUDIO_REG_MAX_NUM           (3)
#define AUDIO_AENC_CHN_MAX_NUM      (1)

/****************************************************************************************/
typedef enum {
    AUDIO_TYPE_PCM = 0,
    AUDIO_TYPE_AAC,
    AUDIO_TYPE_MP3,
    AUDIO_TYPE_G711A,
    AUDIO_TYPE_G711U,
    AUDIO_TYPE_NONE,
}AUDIO_ENCODE_TYPE_E;

typedef int (*AudioAencDataCallback)(int chn, void *data);

typedef struct {
    int (*init)(void);
    int (*deinit)(void);

    int (*audio_aenc_start)(int chn, AudioAencDataCallback pfnAencDataCb);
    int (*audio_aenc_stop)(int chn, AudioAencDataCallback pfnAencDataCb);

    int (*audio_copy_data)(int chn, void *data, MEDIA_PACK_AUDIO *pstPackAudio, int maxSize);

    int (*play_file_start)(char *audioFile, AUDIO_ENCODE_TYPE_E enAudioType, char bLoop);
    int (*play_file_stop)(void);

    ///< 设置AO设备音量
    int (*set_ao_volume)(int volume);

    ///< 设置播放音量,只修改配置,可以修改不同播放模块的音量
    int (*set_play_volume)(PLAY_VOLUME_CONFIG stPlayVol);
    int (*get_play_volume)(PLAY_VOLUME_CONFIG *pstPlayVol);

    int (*talkback_start)(void);
    int (*talkback_data)(unsigned char *pData, int nLen, AUDIO_ENCODE_TYPE_E enAudioType);
    int (*talkback_stop)(void);
}AUDIO_OPS_FUNC_S;

typedef int (*AudioRecvCallback)(int chn, MEDIA_PACK_AUDIO stPackAudio);

typedef struct {
    pthread_mutex_t mutexLock;
    AudioRecvCallback pfnRegAudioCbArry[AUDIO_REG_MAX_NUM];
}AUDIO_REG_ATTR_S;

/****************************************************************************************/
int AudioInit(void);
int AudioDeinit(void);
AUDIO_OPS_FUNC_S *AudioGetOpsHandle(void);
int AudioRegisterRecvData(int chn, AudioRecvCallback pfnRcvAudioCb);
int AudioUnRegisterRecvData(int chn, AudioRecvCallback pfnRcvAudioCb);


/**************************************************************************************
                       如下对讲接口只用于WJA协议调用
**************************************************************************************/
/// @{

/*开始播放对讲初始化音频*/
/*    G711编码          */
/*    8k   采样         */
/*    16位 A-Law        */
int AudioTalkPlaySet(int encType ,int sampRate,  int bitWidth, unsigned int volume);

/* 结束播放对讲关闭喇叭      */
int AudioTalkPlayFinish(void);

/*对讲发送一帧数据*/
int AudioTalkPlayFrame(unsigned char* pDataAdd,int length);

/// @}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */


#endif /* __AUDIO_H__ */
